package com.zhengdongzulin.zuke.app.main.home.city

import com.google.gson.Gson
import com.google.gson.reflect.TypeToken
import com.lxj.androidktx.core.*
import com.zhengdongzulin.zuke.R
import com.zhengdongzulin.zuke.app.data.City
import com.zhengdongzulin.zuke.base.BaseActivity
import com.zhengdongzulin.zuke.base.BaseViewModel
import com.zhengdongzulin.zuke.databinding.ActivitySelectCityBinding

class SelectCityActivity :BaseActivity<BaseViewModel,ActivitySelectCityBinding>() {

    override fun getLayoutResId(): Int = R.layout.activity_select_city

    override fun initVM(): BaseViewModel = BaseViewModel()

    override fun initView() {
        setTitleContent("切换城市")
        var citys = sp().getString("city", "")
        if (!citys.isNullOrEmpty()) {
            var type = object : TypeToken<MutableList<City>>() {}.type
            var mCity = Gson().fromJson<MutableList<City>>(
                citys,
                type
            )
            mView.recyclerView.vertical().bindData(mCity,R.layout.item_city){
                holder, t, position ->
                holder.setText(R.id.city,t.cityName)
            }.itemClick { data:List<City>, holder, position ->
                sp().putString("current_city",data[position].toJson())
                mShareViewModel.city.value = data[position]
                mShareViewModel.apartmentTypeIsChangeForHome.value = true
                mShareViewModel.apartmentTypeIsChangeForApartment.value = true
                mShareViewModel.apartmentTypeIsChangeForFindHouse.value = true
                finish()
            }
        }
    }

    override fun initData() {
        
    }

    override fun initListener() {
        
    }

    override fun startObserve() {
        
    }

}